<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * 供应商提交申请
 * @author 66diqiu-li
 *
 */
class Admin_Adminusercashmsg_model extends CI_Model {

    /**
     * @var 表名称
     */
    private $table;

    public function __construct()
    {
        parent::__construct();
        $this->table  = $this->db->dbprefix("admin_user_cash_msg");
    }

    /**
     * 添加数据
     * @param array $data $data=array('action'=>'add','log'=>'日志信息');
     * @return bool
     */
    function add_row($data=array()){
        $data['sid'] = $GLOBALS['sid'];
        $data['add_time'] = date('Y-m-d H:i:s',time());
        return $this->db->insert($this->table, $data);
    }

    /**
     *
     * 更新数据
     * @param array $data 数据数组
     * @param array $where 更新条件
     */
    function edit_row($data,$where){
        if(!empty($where))$this->db->where($where, NULL, FALSE);
        $res = $this->db->update($this->table,$data);
        return $res;
    }

    /**
     *
     * 删除数据
     * @param array $where 删除条件
     */
    function remove_row($where=array()){
        if(!empty($where))$this->db->where($where, NULL, FALSE);
        return $this->db->delete($this->table);
    }

    /**
     * 获取所有供应商申请信息
     * @param int $page_size 每页显示数量
     * @param int $now_page 第几页
     * @param string $where 选择条件
     * @return array
     */
    function get_list($page_size=20,$now_page=1,$where = ''){
        $this->db->select('id,user_id,user_name,remark,status,add_time,handle_user_name,handle_add_time');
        $this->db->order_by('add_time','DESC');
        if(!empty($where)){
            $this->db->where($where, NULL, FALSE);
        }
        $query = $this->db->get($this->table,$page_size,($now_page-1)*$page_size);
        $data = array();
        foreach($query->result_array() as $row){
            $data[] = $row;
        }
        return $data;
    }

    /**
     *
     * 获取总数量
     * @param array $where 查询条件
     */
    function get_count($where=array()){
        $this->db->select('id');
        $this->db->from($this->table);
        if(!empty($where))$this->db->where($where, NULL, FALSE);
        return $this->db->count_all_results();
    }
}